package Actions;
/*
 * Written by Phat Le
 */
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import Model.ProgramChair;
import Model.Reviewer;
import Model.SubProgramChair;
import View.ManuscriptView;
/**
 * Creates view for subpc to assign paper.
 * @author Phat
 *
 */
public class ViewReviewsAction extends AbstractAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ProgramChair pc;
	private SubProgramChair spc;
	private Reviewer rvw;
	private JTable table;
	private ArrayList<String> reviewList;
	
	public ViewReviewsAction(final JTable a_table, final ProgramChair a_pc) {
		table = a_table;
		pc = a_pc;
		this.putValue(NAME, "PC View Reviews");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_R);
	}
	
	public ViewReviewsAction(final JTable a_table, final SubProgramChair a_spc) {
		table = a_table;
		spc = a_spc;
		this.putValue(NAME, "SPC View Reviews");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_R);
	}
	
	public ViewReviewsAction(final JTable a_table, final Reviewer a_rvw) {
		table = a_table;
		rvw = a_rvw;
		this.putValue(NAME, "RVW View Reviews");
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_R);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(table.getSelectedRow() != -1){
			if(e.getActionCommand().equalsIgnoreCase("PC View Reviews")) {
				reviewList = pc.viewReview(table);
			} else if(e.getActionCommand().equalsIgnoreCase("SPC View Reviews")) {
				reviewList = spc.viewReview(table);
			} else {
				reviewList = rvw.viewReview(table);
			}
			for(int i = 0; i < reviewList.size(); i++){
				ManuscriptView scriptWindow = new ManuscriptView("Review");
				scriptWindow.start(reviewList.get(i));
			}
		} else {
			JOptionPane.showMessageDialog(null, "Please select a manuscript to view its reviews");
		}
	}
}











